
#include<iostream>
#include "CycleLooper.h"
#include <windows.h>

using namespace std;

int main()
{
    // Get a handle to the console output buffer
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    // Enable ANSI escape codes
    DWORD mode;
    GetConsoleMode(hConsole, &mode);
    mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
    SetConsoleMode(hConsole, mode);

    CycleLooper looper;

	std::string s;

	Message msg;

    std::cout << "entre a message:" << std::endl;
	while (true)
	{
        s = "";
		std::cin >> s;
        if (s.empty())
        {
            continue ;
        }

        msg.msg = s;
		if (s[0] == 'x')
		{
            break;
		}
        else if(s[0] == 'h')
        {
            looper.enqueueHead(msg);
        }
        else if(s[0] == 's' )
        {
            if (s.size() >= 2 && s[1] == 's')
            {
                looper.handleSync(msg, true);
            }
            else
            {
                looper.handleSync(msg, false);
            }
        }
		else
		{
            looper.enqueue(msg);
		}
	}

	looper.quit();
	std::cout << "exit!\n";

	return 0;
}
